#include "common.h"

#include "util-gpio.h"

/**
 * 
 * 防断电保护 
 * 
 **/
extern thread_recv_pcie_signal;
void thread_run_keepoff() {
    prctl(PR_SET_NAME, "KEEP_ON");
    // if(KT_OK != gpio_select()) {
    if(KT_OK == gpio_break()) {
        thread_recv_pcie_signal = 0;
	system("umount /mnt/cephfs");
        LOG_ERROR("#ERR: 异常断电, 启用断电保护程序 \n");
        // system("echo '程序断电结束' > ./keepoff.log");  //这种执行比较耗时,程序断电后来不及操作
        return;
    }
    LOG_DEBUG("shutdown \n");
}

void init_keepoff() {
    // 返回KT_OK 则表示收到断电信号
    pthread_t keep_off_id;
    pthread_create(&keep_off_id, NULL, thread_run_keepoff, NULL);
}
